home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 051-075 / scopedisk57 / expand / system.c < prev    next >
C/C++ Source or Header  |  1995-03-19  |  4KB  |  188 lines

  1. /*
  2.  *                            S Y S T E M . C
  3.  *
  4.  *  System dependent routines for EXPAND, a utility to decompress files;
  5.  *  compatible with the public domain COMPRESS v4.0 utility by Spencer W.
  6.  *  Thomas, et al.
  7.  *
  8.  *-----------------------------------------------------------------------
  9.  *  Author: Lyle V. Rains
  10.  *-----------------------------------------------------------------------
  11.  *  Revision History:
  12.  */
  13.  
  14. #define SYSTEM
  15. #include <stdio.h>
  16. #include "system.h"
  17.  
  18. #if DEBUGOUT
  19.   int debug = 0;
  20. #endif
  21.  
  22. static int z_cmp();
  23.  
  24. /* The following two routines are system specific and will
  25.  * need to be modified for other systems.
  26.  */
  27.  
  28. int to_xname(inname)
  29.   char * inname;
  30. /* If inname ends with ZSUFFIX, then ZSUFFIX will be removed from inname
  31.  * and return (YES) otherwise don't modify inname and return (NO)
  32.  */
  33. {
  34.   char *c;
  35.  
  36. # ifdef MSDOS_FNAMES
  37.  
  38.     int size;
  39.     /* If there is no file extension, or if it doesn't end in ZSUFFIX,
  40.      * forget it.  The '.' in the file extension must occur within the
  41.      * last 4 characters, and there can be no path separator after it.
  42.      */
  43.     c = inname + ((size = strlen(inname)) - 4 > 0 ? size - 4 : 0);
  44.     if (  (c = strrchr(c, '.')) == 0
  45.        || strpbrk(c, "/\\")
  46.        || z_cmp(c += strlen(c) - strlen(ZSUFFIX), ZSUFFIX)
  47.        )
  48.     {
  49.       return (NO);
  50.     }
  51.     else {
  52.       *c = '\0';
  53.       return (YES);
  54.     }
  55. # else
  56.     /* Default: just check for ZSUFFIX at the end and get rid of it.
  57.      */
  58.     if (z_cmp(c = inname + strlen(inname) - strlen(ZSUFFIX), ZSUFFIX)) {
  59.       return (NO);
  60.     }
  61.     else {
  62.       *c = '\0';
  63.       return (YES);
  64.     }
  65. # endif
  66. }
  67.  
  68. void to_zname(outname)
  69.   char * outname;
  70. /* Add ZSUFFIX to end of outname. */
  71. {
  72. # ifdef MSDOS_FNAMES
  73.     char *c;
  74.     int size;
  75.  
  76.     /* Find file extension (if any) and append ZSUFFIX to it,
  77.      * overwriting characters in the file extension as necessary.
  78.      */
  79.     c = outname + ((size = strlen(outname)) - 4 > 0 ? size - 4 : 0);
  80.     if ( (c = strrchr(c, '.')) != 0 && strpbrk(c, "/\\") == 0) {
  81.       size = 3 - strlen(ZSUFFIX);      /* Max # extension chars to keep */
  82.       while (*++c != '\0' && size--) /* empty loop */;
  83.       strcpy(c, ZSUFFIX);
  84.     }
  85.     else {
  86.       strcat(outname, "."ZSUFFIX);
  87.     }
  88.     return;
  89. # else
  90.     char *c;
  91.     int maxzlen = MAXNAMELEN - strlen(ZSUFFIX);
  92.     char *filename();
  93.  
  94.     /* Just concatenate ZSUFFIX onto size-adjusted outname */
  95.     c = filename(outname, PATHDELIM);
  96.     if (strlen(c) > maxzlen) {
  97.       c[maxzlen] = '\0';
  98.     }
  99.     strcat(outname, ZSUFFIX);
  100.     return;
  101. # endif
  102. }
  103.  
  104.  
  105. #ifdef M_XENIX
  106.  
  107. # define EPRINTF
  108. # include <varargs.h>
  109.  
  110.   int eprintf(va_alist)
  111.      va_dcl
  112.   {
  113.     va_list args;
  114.     char *format;
  115.     va_start(args);
  116.     format = va_arg(args,char *);
  117.     return (vfprintf(stderr, format, args));
  118.     va_end(args);
  119.   }
  120. #endif
  121.  
  122. #ifdef MWC
  123.  
  124. # define EPRINTF
  125.  
  126.   int eprintf(format)
  127.     char *format;
  128.   {
  129.     return (fprintf(stderr, "%r", &format));
  130.   }
  131.  
  132. #endif
  133.  
  134. #ifdef MCH_AMIGA
  135.  
  136. # define EPRINTF
  137.  
  138.   int eprintf(fmt, args)
  139.     char * fmt;
  140.     unsigned args;
  141.   {
  142.     extern int puterr();
  143.     return (format(puterr, fmt, &args));
  144.   }
  145.  
  146. #endif
  147.  
  148. #ifndef EPRINTF
  149.  
  150. # include <stdarg.h>
  151.  
  152.   int eprintf(format)
  153.     char *format;
  154.   {
  155.     va_list args;
  156.     va_start(args, format);
  157.     return (vfprintf(stderr, format, args));
  158.   }
  159.  
  160. #endif
  161.  
  162.  
  163. static int z_cmp(s1, s2)
  164.   register char *s1, *s2;
  165. {
  166.   register int dif;
  167.  
  168.   while ((dif = CASE(*s1) - CASE(*s2)) == 0 && *s1 != '\0') {
  169.     ++s1;
  170.     ++s2;
  171.   }
  172.   return (dif);
  173. }
  174.  
  175. static char *filename(fullname, pathdelim)
  176.   char *fullname, *pathdelim;
  177.   /* Find the start of the filename after the path (if any) in fullname */
  178. {
  179.   register char *nameptr, *delimptr;
  180.  
  181.   for (nameptr = fullname + strlen(fullname); --nameptr != fullname; ) {
  182.     for (delimptr = pathdelim; *delimptr != '\0'; ++delimptr) {
  183.       if (*delimptr == *nameptr) return (nameptr + 1);
  184.     }
  185.   }
  186.   return (fullname);
  187. }
  188.